home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1998 November / Freeware November 1998.img / dist / fw_elisp-manual-19.idb / usr / freeware / info / elisp-27.z / elisp-27 (.txt)
GNU Info File  |  1998-05-26  |  47KB  |  818 lines

  1. This is Info file elisp, produced by Makeinfo-1.63 from the input file
  2. elisp.texi.
  3.    This version is the edition 2.4.2 of the GNU Emacs Lisp Reference
  4. Manual.  It corresponds to Emacs Version 19.34.
  5.    Published by the Free Software Foundation 59 Temple Place, Suite 330
  6. Boston, MA  02111-1307  USA
  7.    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996 Free Software
  8. Foundation, Inc.
  9.    Permission is granted to make and distribute verbatim copies of this
  10. manual provided the copyright notice and this permission notice are
  11. preserved on all copies.
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided that the
  14. entire resulting derived work is distributed under the terms of a
  15. permission notice identical to this one.
  16.    Permission is granted to copy and distribute translations of this
  17. manual into another language, under the above conditions for modified
  18. versions, except that this permission notice may be stated in a
  19. translation approved by the Foundation.
  20.    Permission is granted to copy and distribute modified versions of
  21. this manual under the conditions for verbatim copying, provided also
  22. that the section entitled "GNU General Public License" is included
  23. exactly as in the original, and provided that the entire resulting
  24. derived work is distributed under the terms of a permission notice
  25. identical to this one.
  26.    Permission is granted to copy and distribute translations of this
  27. manual into another language, under the above conditions for modified
  28. versions, except that the section entitled "GNU General Public License"
  29. may be included in a translation approved by the Free Software
  30. Foundation instead of in the original English.
  31. File: elisp,  Node: Margins,  Next: Auto Filling,  Prev: Filling,  Up: Text
  32. Margins for Filling
  33. ===================
  34.  - User Option: fill-prefix
  35.      This variable specifies a string of text that appears at the
  36.      beginning of normal text lines and should be disregarded when
  37.      filling them.  Any line that fails to start with the fill prefix
  38.      is considered the start of a paragraph; so is any line that starts
  39.      with the fill prefix followed by additional whitespace.  Lines
  40.      that start with the fill prefix but no additional whitespace are
  41.      ordinary text lines that can be filled together.  The resulting
  42.      filled lines also start with the fill prefix.
  43.      The fill prefix follows the left margin whitespace, if any.
  44.  - User Option: fill-column
  45.      This buffer-local variable specifies the maximum width of filled
  46.      lines.  Its value should be an integer, which is a number of
  47.      columns.  All the filling, justification and centering commands
  48.      are affected by this variable, including Auto Fill mode (*note
  49.      Auto Filling::.).
  50.      As a practical matter, if you are writing text for other people to
  51.      read, you should set `fill-column' to no more than 70.  Otherwise
  52.      the line will be too long for people to read comfortably, and this
  53.      can make the text seem clumsy.
  54.  - Variable: default-fill-column
  55.      The value of this variable is the default value for `fill-column'
  56.      in buffers that do not override it.  This is the same as
  57.      `(default-value 'fill-column)'.
  58.      The default value for `default-fill-column' is 70.
  59.  - Command: set-left-margin FROM TO MARGIN
  60.      This sets the `left-margin' property on the text from FROM to TO
  61.      to the value MARGIN.  If Auto Fill mode is enabled, this command
  62.      also refills the region to fit the new margin.
  63.  - Command: set-right-margin FROM TO MARGIN
  64.      This sets the `right-margin' property on the text from FROM to TO
  65.      to the value MARGIN.  If Auto Fill mode is enabled, this command
  66.      also refills the region to fit the new margin.
  67.  - Function: current-left-margin
  68.      This function returns the proper left margin value to use for
  69.      filling the text around point.  The value is the sum of the
  70.      `left-margin' property of the character at the start of the
  71.      current line (or zero if none), and the value of the variable
  72.      `left-margin'.
  73.  - Function: current-fill-column
  74.      This function returns the proper fill column value to use for
  75.      filling the text around point.  The value is the value of the
  76.      `fill-column' variable, minus the value of the `right-margin'
  77.      property of the character after point.
  78.  - Command: move-to-left-margin &optional N FORCE
  79.      This function moves point to the left margin of the current line.
  80.      The column moved to is determined by calling the function
  81.      `current-left-margin'.  If the argument N is non-`nil',
  82.      `move-to-left-margin' moves forward N-1 lines first.
  83.      If FORCE is non-`nil', that says to fix the line's indentation if
  84.      that doesn't match the left margin value.
  85.  - Function: delete-to-left-margin FROM TO
  86.      This function removes left margin indentation from the text
  87.      between FROM and TO.  The amount of indentation to delete is
  88.      determined by calling `current-left-margin'.  In no case does this
  89.      function delete non-whitespace.
  90.  - Function: indent-to-left-margin
  91.      This is the default `indent-line-function', used in Fundamental
  92.      mode, Text mode, etc.  Its effect is to adjust the indentation at
  93.      the beginning of the current line to the value specified by the
  94.      variable `left-margin'.  This may involve either inserting or
  95.      deleting whitespace.
  96.  - Variable: left-margin
  97.      This variable specifies the base left margin column.  In
  98.      Fundamental mode, LFD indents to this column.  This variable
  99.      automatically becomes buffer-local when set in any fashion.
  100. File: elisp,  Node: Auto Filling,  Next: Sorting,  Prev: Margins,  Up: Text
  101. Auto Filling
  102. ============
  103.    Auto Fill mode is a minor mode that fills lines automatically as text
  104. is inserted.  This section describes the hook used by Auto Fill mode.
  105. For a description of functions that you can call explicitly to fill and
  106. justify existing text, see *Note Filling::.
  107.    Auto Fill mode also enables the functions that change the margins and
  108. justification style to refill portions of the text.  *Note Margins::.
  109.  - Variable: auto-fill-function
  110.      The value of this variable should be a function (of no arguments)
  111.      to be called after self-inserting a space or a newline.  It may be
  112.      `nil', in which case nothing special is done in that case.
  113.      The value of `auto-fill-function' is `do-auto-fill' when Auto-Fill
  114.      mode is enabled.  That is a function whose sole purpose is to
  115.      implement the usual strategy for breaking a line.
  116.           In older Emacs versions, this variable was named
  117.           `auto-fill-hook', but since it is not called with the
  118.           standard convention for hooks, it was renamed to
  119.           `auto-fill-function' in version 19.
  120.  - Variable: normal-auto-fill-function
  121.      This variable specifies the function to use for
  122.      `auto-fill-function', if and when Auto Fill is turned on.  Major
  123.      modes can set this locally to alter how Auto Fill works.
  124. File: elisp,  Node: Sorting,  Next: Columns,  Prev: Auto Filling,  Up: Text
  125. Sorting Text
  126. ============
  127.    The sorting functions described in this section all rearrange text in
  128. a buffer.  This is in contrast to the function `sort', which rearranges
  129. the order of the elements of a list (*note Rearrangement::.).  The
  130. values returned by these functions are not meaningful.
  131.  - Function: sort-subr REVERSE NEXTRECFUN ENDRECFUN &optional
  132.           STARTKEYFUN ENDKEYFUN
  133.      This function is the general text-sorting routine that divides a
  134.      buffer into records and sorts them.  Most of the commands in this
  135.      section use this function.
  136.      To understand how `sort-subr' works, consider the whole accessible
  137.      portion of the buffer as being divided into disjoint pieces called
  138.      "sort records".  The records may or may not be contiguous; they may
  139.      not overlap.  A portion of each sort record (perhaps all of it) is
  140.      designated as the sort key.  Sorting rearranges the records in
  141.      order by their sort keys.
  142.      Usually, the records are rearranged in order of ascending sort key.
  143.      If the first argument to the `sort-subr' function, REVERSE, is
  144.      non-`nil', the sort records are rearranged in order of descending
  145.      sort key.
  146.      The next four arguments to `sort-subr' are functions that are
  147.      called to move point across a sort record.  They are called many
  148.      times from within `sort-subr'.
  149.        1. NEXTRECFUN is called with point at the end of a record.  This
  150.           function moves point to the start of the next record.  The
  151.           first record is assumed to start at the position of point
  152.           when `sort-subr' is called.  Therefore, you should usually
  153.           move point to the beginning of the buffer before calling
  154.           `sort-subr'.
  155.           This function can indicate there are no more sort records by
  156.           leaving point at the end of the buffer.
  157.        2. ENDRECFUN is called with point within a record.  It moves
  158.           point to the end of the record.
  159.        3. STARTKEYFUN is called to move point from the start of a
  160.           record to the start of the sort key.  This argument is
  161.           optional; if it is omitted, the whole record is the sort key.
  162.           If supplied, the function should either return a non-`nil'
  163.           value to be used as the sort key, or return `nil' to indicate
  164.           that the sort key is in the buffer starting at point.  In the
  165.           latter case, ENDKEYFUN is called to find the end of the sort
  166.           key.
  167.        4. ENDKEYFUN is called to move point from the start of the sort
  168.           key to the end of the sort key.  This argument is optional.
  169.           If STARTKEYFUN returns `nil' and this argument is omitted (or
  170.           `nil'), then the sort key extends to the end of the record.
  171.           There is no need for ENDKEYFUN if STARTKEYFUN returns a
  172.           non-`nil' value.
  173.      As an example of `sort-subr', here is the complete function
  174.      definition for `sort-lines':
  175.           ;; Note that the first two lines of doc string
  176.           ;; are effectively one line when viewed by a user.
  177.           (defun sort-lines (reverse beg end)
  178.             "Sort lines in region alphabetically.
  179.           Called from a program, there are three arguments:
  180.           REVERSE (non-nil means reverse order),
  181.           and BEG and END (the region to sort)."
  182.             (interactive "P\nr")
  183.             (save-restriction
  184.               (narrow-to-region beg end)
  185.               (goto-char (point-min))
  186.               (sort-subr reverse
  187.                          'forward-line
  188.                          'end-of-line)))
  189.      Here `forward-line' moves point to the start of the next record,
  190.      and `end-of-line' moves point to the end of record.  We do not pass
  191.      the arguments STARTKEYFUN and ENDKEYFUN, because the entire record
  192.      is used as the sort key.
  193.      The `sort-paragraphs' function is very much the same, except that
  194.      its `sort-subr' call looks like this:
  195.           (sort-subr reverse
  196.                      (function
  197.                       (lambda ()
  198.                         (skip-chars-forward "\n \t\f")))
  199.                      'forward-paragraph)
  200.  - Command: sort-regexp-fields REVERSE RECORD-REGEXP KEY-REGEXP START
  201.           END
  202.      This command sorts the region between START and END alphabetically
  203.      as specified by RECORD-REGEXP and KEY-REGEXP.  If REVERSE is a
  204.      negative integer, then sorting is in reverse order.
  205.      Alphabetical sorting means that two sort keys are compared by
  206.      comparing the first characters of each, the second characters of
  207.      each, and so on.  If a mismatch is found, it means that the sort
  208.      keys are unequal; the sort key whose character is less at the
  209.      point of first mismatch is the lesser sort key.  The individual
  210.      characters are compared according to their numerical values.
  211.      Since Emacs uses the ASCII character set, the ordering in that set
  212.      determines alphabetical order.
  213.      The value of the RECORD-REGEXP argument specifies how to divide
  214.      the buffer into sort records.  At the end of each record, a search
  215.      is done for this regular expression, and the text that matches it
  216.      is the next record.  For example, the regular expression `^.+$',
  217.      which matches lines with at least one character besides a newline,
  218.      would make each such line into a sort record.  *Note Regular
  219.      Expressions::, for a description of the syntax and meaning of
  220.      regular expressions.
  221.      The value of the KEY-REGEXP argument specifies what part of each
  222.      record is the sort key.  The KEY-REGEXP could match the whole
  223.      record, or only a part.  In the latter case, the rest of the
  224.      record has no effect on the sorted order of records, but it is
  225.      carried along when the record moves to its new position.
  226.      The KEY-REGEXP argument can refer to the text matched by a
  227.      subexpression of RECORD-REGEXP, or it can be a regular expression
  228.      on its own.
  229.      If KEY-REGEXP is:
  230.     `\DIGIT'
  231.           then the text matched by the DIGITth `\(...\)' parenthesis
  232.           grouping in RECORD-REGEXP is the sort key.
  233.     `\&'
  234.           then the whole record is the sort key.
  235.     a regular expression
  236.           then `sort-regexp-fields' searches for a match for the regular
  237.           expression within the record.  If such a match is found, it
  238.           is the sort key.  If there is no match for KEY-REGEXP within
  239.           a record then that record is ignored, which means its
  240.           position in the buffer is not changed.  (The other records
  241.           may move around it.)
  242.      For example, if you plan to sort all the lines in the region by the
  243.      first word on each line starting with the letter `f', you should
  244.      set RECORD-REGEXP to `^.*$' and set KEY-REGEXP to `\<f\w*\>'.  The
  245.      resulting expression looks like this:
  246.           (sort-regexp-fields nil "^.*$" "\\<f\\w*\\>"
  247.                               (region-beginning)
  248.                               (region-end))
  249.      If you call `sort-regexp-fields' interactively, it prompts for
  250.      RECORD-REGEXP and KEY-REGEXP in the minibuffer.
  251.  - Command: sort-lines REVERSE START END
  252.      This command alphabetically sorts lines in the region between
  253.      START and END.  If REVERSE is non-`nil', the sort is in reverse
  254.      order.
  255.  - Command: sort-paragraphs REVERSE START END
  256.      This command alphabetically sorts paragraphs in the region between
  257.      START and END.  If REVERSE is non-`nil', the sort is in reverse
  258.      order.
  259.  - Command: sort-pages REVERSE START END
  260.      This command alphabetically sorts pages in the region between
  261.      START and END.  If REVERSE is non-`nil', the sort is in reverse
  262.      order.
  263.  - Command: sort-fields FIELD START END
  264.      This command sorts lines in the region between START and END,
  265.      comparing them alphabetically by the FIELDth field of each line.
  266.      Fields are separated by whitespace and numbered starting from 1.
  267.      If FIELD is negative, sorting is by the -FIELDth field from the
  268.      end of the line.  This command is useful for sorting tables.
  269.  - Command: sort-numeric-fields FIELD START END
  270.      This command sorts lines in the region between START and END,
  271.      comparing them numerically by the FIELDth field of each line.  The
  272.      specified field must contain a number in each line of the region.
  273.      Fields are separated by whitespace and numbered starting from 1.
  274.      If FIELD is negative, sorting is by the -FIELDth field from the
  275.      end of the line.  This command is useful for sorting tables.
  276.  - Command: sort-columns REVERSE &optional BEG END
  277.      This command sorts the lines in the region between BEG and END,
  278.      comparing them alphabetically by a certain range of columns.  The
  279.      column positions of BEG and END bound the range of columns to sort
  280.      on.
  281.      If REVERSE is non-`nil', the sort is in reverse order.
  282.      One unusual thing about this command is that the entire line
  283.      containing position BEG, and the entire line containing position
  284.      END, are included in the region sorted.
  285.      Note that `sort-columns' uses the `sort' utility program, and so
  286.      cannot work properly on text containing tab characters.  Use `M-x
  287.      `untabify'' to convert tabs to spaces before sorting.
  288. File: elisp,  Node: Columns,  Next: Indentation,  Prev: Sorting,  Up: Text
  289. Counting Columns
  290. ================
  291.    The column functions convert between a character position (counting
  292. characters from the beginning of the buffer) and a column position
  293. (counting screen characters from the beginning of a line).
  294.    A character counts according to the number of columns it occupies on
  295. the screen.  This means control characters count as occupying 2 or 4
  296. columns, depending upon the value of `ctl-arrow', and tabs count as
  297. occupying a number of columns that depends on the value of `tab-width'
  298. and on the column where the tab begins.  *Note Usual Display::.
  299.    Column number computations ignore the width of the window and the
  300. amount of horizontal scrolling.  Consequently, a column value can be
  301. arbitrarily high.  The first (or leftmost) column is numbered 0.
  302.  - Function: current-column
  303.      This function returns the horizontal position of point, measured in
  304.      columns, counting from 0 at the left margin.  The column position
  305.      is the sum of the widths of all the displayed representations of
  306.      the characters between the start of the current line and point.
  307.      For an example of using `current-column', see the description of
  308.      `count-lines' in *Note Text Lines::.
  309.  - Function: move-to-column COLUMN &optional FORCE
  310.      This function moves point to COLUMN in the current line.  The
  311.      calculation of COLUMN takes into account the widths of the
  312.      displayed representations of the characters between the start of
  313.      the line and point.
  314.      If column COLUMN is beyond the end of the line, point moves to the
  315.      end of the line.  If COLUMN is negative, point moves to the
  316.      beginning of the line.
  317.      If it is impossible to move to column COLUMN because that is in
  318.      the middle of a multicolumn character such as a tab, point moves
  319.      to the end of that character.  However, if FORCE is non-`nil', and
  320.      COLUMN is in the middle of a tab, then `move-to-column' converts
  321.      the tab into spaces so that it can move precisely to column
  322.      COLUMN.  Other multicolumn characters can cause anomalies despite
  323.      FORCE, since there is no way to split them.
  324.      The argument FORCE also has an effect if the line isn't long
  325.      enough to reach column COLUMN; in that case, it says to add
  326.      whitespace at the end of the line to reach that column.
  327.      If COLUMN is not an integer, an error is signaled.
  328.      The return value is the column number actually moved to.
  329. File: elisp,  Node: Indentation,  Next: Case Changes,  Prev: Columns,  Up: Text
  330. Indentation
  331. ===========
  332.    The indentation functions are used to examine, move to, and change
  333. whitespace that is at the beginning of a line.  Some of the functions
  334. can also change whitespace elsewhere on a line.  Columns and indentation
  335. count from zero at the left margin.
  336. * Menu:
  337. * Primitive Indent::      Functions used to count and insert indentation.
  338. * Mode-Specific Indent::  Customize indentation for different modes.
  339. * Region Indent::         Indent all the lines in a region.
  340. * Relative Indent::       Indent the current line based on previous lines.
  341. * Indent Tabs::           Adjustable, typewriter-like tab stops.
  342. * Motion by Indent::      Move to first non-blank character.
  343. File: elisp,  Node: Primitive Indent,  Next: Mode-Specific Indent,  Up: Indentation
  344. Indentation Primitives
  345. ----------------------
  346.    This section describes the primitive functions used to count and
  347. insert indentation.  The functions in the following sections use these
  348. primitives.
  349.  - Function: current-indentation
  350.      This function returns the indentation of the current line, which is
  351.      the horizontal position of the first nonblank character.  If the
  352.      contents are entirely blank, then this is the horizontal position
  353.      of the end of the line.
  354.  - Command: indent-to COLUMN &optional MINIMUM
  355.      This function indents from point with tabs and spaces until COLUMN
  356.      is reached.  If MINIMUM is specified and non-`nil', then at least
  357.      that many spaces are inserted even if this requires going beyond
  358.      COLUMN.  Otherwise the function does nothing if point is already
  359.      beyond COLUMN.  The value is the column at which the inserted
  360.      indentation ends.
  361.      The inserted whitespace characters inherit text properties from the
  362.      surrounding text (usually, from the preceding text only).  *Note
  363.      Sticky Properties::.
  364.  - User Option: indent-tabs-mode
  365.      If this variable is non-`nil', indentation functions can insert
  366.      tabs as well as spaces.  Otherwise, they insert only spaces.
  367.      Setting this variable automatically makes it local to the current
  368.      buffer.
  369. File: elisp,  Node: Mode-Specific Indent,  Next: Region Indent,  Prev: Primitive Indent,  Up: Indentation
  370. Indentation Controlled by Major Mode
  371. ------------------------------------
  372.    An important function of each major mode is to customize the TAB key
  373. to indent properly for the language being edited.  This section
  374. describes the mechanism of the TAB key and how to control it.  The
  375. functions in this section return unpredictable values.
  376.  - Variable: indent-line-function
  377.      This variable's value is the function to be used by TAB (and
  378.      various commands) to indent the current line.  The command
  379.      `indent-according-to-mode' does no more than call this function.
  380.      In Lisp mode, the value is the symbol `lisp-indent-line'; in C
  381.      mode, `c-indent-line'; in Fortran mode, `fortran-indent-line'.  In
  382.      Fundamental mode, Text mode, and many other modes with no standard
  383.      for indentation, the value is `indent-to-left-margin' (which is the
  384.      default value).
  385.  - Command: indent-according-to-mode
  386.      This command calls the function in `indent-line-function' to
  387.      indent the current line in a way appropriate for the current major
  388.      mode.
  389.  - Command: indent-for-tab-command
  390.      This command calls the function in `indent-line-function' to indent
  391.      the current line; except that if that function is
  392.      `indent-to-left-margin', it calls `insert-tab' instead.  (That is
  393.      a trivial command that inserts a tab character.)
  394.  - Command: newline-and-indent
  395.      This function inserts a newline, then indents the new line (the one
  396.      following the newline just inserted) according to the major mode.
  397.      It does indentation by calling the current `indent-line-function'.
  398.      In programming language modes, this is the same thing TAB does,
  399.      but in some text modes, where TAB inserts a tab,
  400.      `newline-and-indent' indents to the column specified by
  401.      `left-margin'.
  402.  - Command: reindent-then-newline-and-indent
  403.      This command reindents the current line, inserts a newline at
  404.      point, and then reindents the new line (the one following the
  405.      newline just inserted).
  406.      This command does indentation on both lines according to the
  407.      current major mode, by calling the current value of
  408.      `indent-line-function'.  In programming language modes, this is
  409.      the same thing TAB does, but in some text modes, where TAB inserts
  410.      a tab, `reindent-then-newline-and-indent' indents to the column
  411.      specified by `left-margin'.
  412. File: elisp,  Node: Region Indent,  Next: Relative Indent,  Prev: Mode-Specific Indent,  Up: Indentation
  413. Indenting an Entire Region
  414. --------------------------
  415.    This section describes commands that indent all the lines in the
  416. region.  They return unpredictable values.
  417.  - Command: indent-region START END TO-COLUMN
  418.      This command indents each nonblank line starting between START
  419.      (inclusive) and END (exclusive).  If TO-COLUMN is `nil',
  420.      `indent-region' indents each nonblank line by calling the current
  421.      mode's indentation function, the value of `indent-line-function'.
  422.      If TO-COLUMN is non-`nil', it should be an integer specifying the
  423.      number of columns of indentation; then this function gives each
  424.      line exactly that much indentation, by either adding or deleting
  425.      whitespace.
  426.      If there is a fill prefix, `indent-region' indents each line by
  427.      making it start with the fill prefix.
  428.  - Variable: indent-region-function
  429.      The value of this variable is a function that can be used by
  430.      `indent-region' as a short cut.  You should design the function so
  431.      that it will produce the same results as indenting the lines of the
  432.      region one by one, but presumably faster.
  433.      If the value is `nil', there is no short cut, and `indent-region'
  434.      actually works line by line.
  435.      A short-cut function is useful in modes such as C mode and Lisp
  436.      mode, where the `indent-line-function' must scan from the
  437.      beginning of the function definition: applying it to each line
  438.      would be quadratic in time.  The short cut can update the scan
  439.      information as it moves through the lines indenting them; this
  440.      takes linear time.  In a mode where indenting a line individually
  441.      is fast, there is no need for a short cut.
  442.      `indent-region' with a non-`nil' argument TO-COLUMN has a
  443.      different meaning and does not use this variable.
  444.  - Command: indent-rigidly START END COUNT
  445.      This command indents all lines starting between START (inclusive)
  446.      and END (exclusive) sideways by COUNT columns.  This "preserves
  447.      the shape" of the affected region, moving it as a rigid unit.
  448.      Consequently, this command is useful not only for indenting
  449.      regions of unindented text, but also for indenting regions of
  450.      formatted code.
  451.      For example, if COUNT is 3, this command adds 3 columns of
  452.      indentation to each of the lines beginning in the region specified.
  453.      In Mail mode, `C-c C-y' (`mail-yank-original') uses
  454.      `indent-rigidly' to indent the text copied from the message being
  455.      replied to.
  456.  - Function: indent-code-rigidly START END COLUMNS &optional
  457.           NOCHANGE-REGEXP
  458.      This is like `indent-rigidly', except that it doesn't alter lines
  459.      that start within strings or comments.
  460.      In addition, it doesn't alter a line if NOCHANGE-REGEXP matches at
  461.      the beginning of the line (if NOCHANGE-REGEXP is non-`nil').
  462. File: elisp,  Node: Relative Indent,  Next: Indent Tabs,  Prev: Region Indent,  Up: Indentation
  463. Indentation Relative to Previous Lines
  464. --------------------------------------
  465.    This section describes two commands that indent the current line
  466. based on the contents of previous lines.
  467.  - Command: indent-relative &optional UNINDENTED-OK
  468.      This command inserts whitespace at point, extending to the same
  469.      column as the next "indent point" of the previous nonblank line.
  470.      An indent point is a non-whitespace character following
  471.      whitespace.  The next indent point is the first one at a column
  472.      greater than the current column of point.  For example, if point
  473.      is underneath and to the left of the first non-blank character of
  474.      a line of text, it moves to that column by inserting whitespace.
  475.      If the previous nonblank line has no next indent point (i.e., none
  476.      at a great enough column position), `indent-relative' either does
  477.      nothing (if UNINDENTED-OK is non-`nil') or calls
  478.      `tab-to-tab-stop'.  Thus, if point is underneath and to the right
  479.      of the last column of a short line of text, this command ordinarily
  480.      moves point to the next tab stop by inserting whitespace.
  481.      The return value of `indent-relative' is unpredictable.
  482.      In the following example, point is at the beginning of the second
  483.      line:
  484.                       This line is indented twelve spaces.
  485.           -!-The quick brown fox jumped.
  486.      Evaluation of the expression `(indent-relative nil)' produces the
  487.      following:
  488.                       This line is indented twelve spaces.
  489.                       -!-The quick brown fox jumped.
  490.      In this example, point is between the `m' and `p' of `jumped':
  491.                       This line is indented twelve spaces.
  492.           The quick brown fox jum-!-ped.
  493.      Evaluation of the expression `(indent-relative nil)' produces the
  494.      following:
  495.                       This line is indented twelve spaces.
  496.           The quick brown fox jum  -!-ped.
  497.  - Command: indent-relative-maybe
  498.      This command indents the current line like the previous nonblank
  499.      line.  It calls `indent-relative' with `t' as the UNINDENTED-OK
  500.      argument.  The return value is unpredictable.
  501.      If the previous nonblank line has no indent points beyond the
  502.      current column, this command does nothing.
  503. File: elisp,  Node: Indent Tabs,  Next: Motion by Indent,  Prev: Relative Indent,  Up: Indentation
  504. Adjustable "Tab Stops"
  505. ----------------------
  506.    This section explains the mechanism for user-specified "tab stops"
  507. and the mechanisms that use and set them.  The name "tab stops" is used
  508. because the feature is similar to that of the tab stops on a
  509. typewriter.  The feature works by inserting an appropriate number of
  510. spaces and tab characters to reach the next tab stop column; it does not
  511. affect the display of tab characters in the buffer (*note Usual
  512. Display::.).  Note that the TAB character as input uses this tab stop
  513. feature only in a few major modes, such as Text mode.
  514.  - Command: tab-to-tab-stop
  515.      This command inserts spaces or tabs up to the next tab stop column
  516.      defined by `tab-stop-list'.  It searches the list for an element
  517.      greater than the current column number, and uses that element as
  518.      the column to indent to.  It does nothing if no such element is
  519.      found.
  520.  - User Option: tab-stop-list
  521.      This variable is the list of tab stop columns used by
  522.      `tab-to-tab-stops'.  The elements should be integers in increasing
  523.      order.  The tab stop columns need not be evenly spaced.
  524.      Use `M-x edit-tab-stops' to edit the location of tab stops
  525.      interactively.
  526. File: elisp,  Node: Motion by Indent,  Prev: Indent Tabs,  Up: Indentation
  527. Indentation-Based Motion Commands
  528. ---------------------------------
  529.    These commands, primarily for interactive use, act based on the
  530. indentation in the text.
  531.  - Command: back-to-indentation
  532.      This command moves point to the first non-whitespace character in
  533.      the current line (which is the line in which point is located).
  534.      It returns `nil'.
  535.  - Command: backward-to-indentation ARG
  536.      This command moves point backward ARG lines and then to the first
  537.      nonblank character on that line.  It returns `nil'.
  538.  - Command: forward-to-indentation ARG
  539.      This command moves point forward ARG lines and then to the first
  540.      nonblank character on that line.  It returns `nil'.
  541. File: elisp,  Node: Case Changes,  Next: Text Properties,  Prev: Indentation,  Up: Text
  542. Case Changes
  543. ============
  544.    The case change commands described here work on text in the current
  545. buffer.  *Note Character Case::, for case conversion commands that work
  546. on strings and characters.  *Note Case Table::, for how to customize
  547. which characters are upper or lower case and how to convert them.
  548.  - Command: capitalize-region START END
  549.      This function capitalizes all words in the region defined by START
  550.      and END.  To capitalize means to convert each word's first
  551.      character to upper case and convert the rest of each word to lower
  552.      case.  The function returns `nil'.
  553.      If one end of the region is in the middle of a word, the part of
  554.      the word within the region is treated as an entire word.
  555.      When `capitalize-region' is called interactively, START and END
  556.      are point and the mark, with the smallest first.
  557.           ---------- Buffer: foo ----------
  558.           This is the contents of the 5th foo.
  559.           ---------- Buffer: foo ----------
  560.           
  561.           (capitalize-region 1 44)
  562.           => nil
  563.           
  564.           ---------- Buffer: foo ----------
  565.           This Is The Contents Of The 5th Foo.
  566.           ---------- Buffer: foo ----------
  567.  - Command: downcase-region START END
  568.      This function converts all of the letters in the region defined by
  569.      START and END to lower case.  The function returns `nil'.
  570.      When `downcase-region' is called interactively, START and END are
  571.      point and the mark, with the smallest first.
  572.  - Command: upcase-region START END
  573.      This function converts all of the letters in the region defined by
  574.      START and END to upper case.  The function returns `nil'.
  575.      When `upcase-region' is called interactively, START and END are
  576.      point and the mark, with the smallest first.
  577.  - Command: capitalize-word COUNT
  578.      This function capitalizes COUNT words after point, moving point
  579.      over as it does.  To capitalize means to convert each word's first
  580.      character to upper case and convert the rest of each word to lower
  581.      case.  If COUNT is negative, the function capitalizes the -COUNT
  582.      previous words but does not move point.  The value is `nil'.
  583.      If point is in the middle of a word, the part of the word before
  584.      point is ignored when moving forward.  The rest is treated as an
  585.      entire word.
  586.      When `capitalize-word' is called interactively, COUNT is set to
  587.      the numeric prefix argument.
  588.  - Command: downcase-word COUNT
  589.      This function converts the COUNT words after point to all lower
  590.      case, moving point over as it does.  If COUNT is negative, it
  591.      converts the -COUNT previous words but does not move point.  The
  592.      value is `nil'.
  593.      When `downcase-word' is called interactively, COUNT is set to the
  594.      numeric prefix argument.
  595.  - Command: upcase-word COUNT
  596.      This function converts the COUNT words after point to all upper
  597.      case, moving point over as it does.  If COUNT is negative, it
  598.      converts the -COUNT previous words but does not move point.  The
  599.      value is `nil'.
  600.      When `upcase-word' is called interactively, COUNT is set to the
  601.      numeric prefix argument.
  602. File: elisp,  Node: Text Properties,  Next: Substitution,  Prev: Case Changes,  Up: Text
  603. Text Properties
  604. ===============
  605.    Each character position in a buffer or a string can have a "text
  606. property list", much like the property list of a symbol (*note Property
  607. Lists::.).  The properties belong to a particular character at a
  608. particular place, such as, the letter `T' at the beginning of this
  609. sentence or the first `o' in `foo'--if the same character occurs in two
  610. different places, the two occurrences generally have different
  611. properties.
  612.    Each property has a name and a value.  Both of these can be any Lisp
  613. object, but the name is normally a symbol.  The usual way to access the
  614. property list is to specify a name and ask what value corresponds to it.
  615.    If a character has a `category' property, we call it the "category"
  616. of the character.  It should be a symbol.  The properties of the symbol
  617. serve as defaults for the properties of the character.
  618.    Copying text between strings and buffers preserves the properties
  619. along with the characters; this includes such diverse functions as
  620. `substring', `insert', and `buffer-substring'.
  621. * Menu:
  622. * Examining Properties::    Looking at the properties of one character.
  623. * Changing Properties::        Setting the properties of a range of text.
  624. * Property Search::        Searching for where a property changes value.
  625. * Special Properties::        Particular properties with special meanings.
  626. * Format Properties::           Properties for representing formatting of text.
  627. * Sticky Properties::           How inserted text gets properties from
  628.                                   neighboring text.
  629. * Saving Properties::           Saving text properties in files, and reading
  630.                                   them back.
  631. * Lazy Properties::             Computing text properties in a lazy fashion
  632.                                   only when text is examined.
  633. * Not Intervals::        Why text properties do not use
  634.                   Lisp-visible text intervals.
  635. File: elisp,  Node: Examining Properties,  Next: Changing Properties,  Up: Text Properties
  636. Examining Text Properties
  637. -------------------------
  638.    The simplest way to examine text properties is to ask for the value
  639. of a particular property of a particular character.  For that, use
  640. `get-text-property'.  Use `text-properties-at' to get the entire
  641. property list of a character.  *Note Property Search::, for functions
  642. to examine the properties of a number of characters at once.
  643.    These functions handle both strings and buffers.  Keep in mind that
  644. positions in a string start from 0, whereas positions in a buffer start
  645. from 1.
  646.  - Function: get-text-property POS PROP &optional OBJECT
  647.      This function returns the value of the PROP property of the
  648.      character after position POS in OBJECT (a buffer or string).  The
  649.      argument OBJECT is optional and defaults to the current buffer.
  650.      If there is no PROP property strictly speaking, but the character
  651.      has a category that is a symbol, then `get-text-property' returns
  652.      the PROP property of that symbol.
  653.  - Function: get-char-property POS PROP &optional OBJECT
  654.      This function is like `get-text-property', except that it checks
  655.      overlays first and then text properties.  *Note Overlays::.
  656.      The argument OBJECT may be a string, a buffer, or a window.  If it
  657.      is a window, then the buffer displayed in that window is used for
  658.      text properties and overlays, but only the overlays active for
  659.      that window are considered.  If OBJECT is a buffer, then all
  660.      overlays in that buffer are considered, as well as text
  661.      properties.  If OBJECT is a string, only text properties are
  662.      considered, since strings never have overlays.
  663.  - Function: text-properties-at POSITION &optional OBJECT
  664.      This function returns the entire property list of the character at
  665.      POSITION in the string or buffer OBJECT.  If OBJECT is `nil', it
  666.      defaults to the current buffer.
  667.  - Variable: default-text-properties
  668.      This variable holds a property list giving default values for text
  669.      properties.  Whenever a character does not specify a value for a
  670.      property, neither directly nor through a category symbol, the value
  671.      stored in this list is used instead.  Here is an example:
  672.           (setq default-text-properties '(foo 69))
  673.           ;; Make sure character 1 has no properties of its own.
  674.           (set-text-properties 1 2 nil)
  675.           ;; What we get, when we ask, is the default value.
  676.           (get-text-property 1 'foo)
  677.                => 69
  678. File: elisp,  Node: Changing Properties,  Next: Property Search,  Prev: Examining Properties,  Up: Text Properties
  679. Changing Text Properties
  680. ------------------------
  681.    The primitives for changing properties apply to a specified range of
  682. text.  The function `set-text-properties' (see end of section) sets the
  683. entire property list of the text in that range; more often, it is
  684. useful to add, change, or delete just certain properties specified by
  685. name.
  686.    Since text properties are considered part of the buffer's contents,
  687. and can affect how the buffer looks on the screen, any change in the
  688. text properties is considered a buffer modification.  Buffer text
  689. property changes are undoable (*note Undo::.).
  690.  - Function: put-text-property START END PROP VALUE &optional OBJECT
  691.      This function sets the PROP property to VALUE for the text between
  692.      START and END in the string or buffer OBJECT.  If OBJECT is `nil',
  693.      it defaults to the current buffer.
  694.  - Function: add-text-properties START END PROPS &optional OBJECT
  695.      This function modifies the text properties for the text between
  696.      START and END in the string or buffer OBJECT.  If OBJECT is `nil',
  697.      it defaults to the current buffer.
  698.      The argument PROPS specifies which properties to change.  It
  699.      should have the form of a property list (*note Property Lists::.):
  700.      a list whose elements include the property names followed
  701.      alternately by the corresponding values.
  702.      The return value is `t' if the function actually changed some
  703.      property's value; `nil' otherwise (if PROPS is `nil' or its values
  704.      agree with those in the text).
  705.      For example, here is how to set the `comment' and `face'
  706.      properties of a range of text:
  707.           (add-text-properties START END
  708.                                '(comment t face highlight))
  709.  - Function: remove-text-properties START END PROPS &optional OBJECT
  710.      This function deletes specified text properties from the text
  711.      between START and END in the string or buffer OBJECT.  If OBJECT
  712.      is `nil', it defaults to the current buffer.
  713.      The argument PROPS specifies which properties to delete.  It
  714.      should have the form of a property list (*note Property Lists::.):
  715.      a list whose elements are property names alternating with
  716.      corresponding values.  But only the names matter--the values that
  717.      accompany them are ignored.  For example, here's how to remove the
  718.      `face' property.
  719.           (remove-text-properties START END '(face nil))
  720.      The return value is `t' if the function actually changed some
  721.      property's value; `nil' otherwise (if PROPS is `nil' or if no
  722.      character in the specified text had any of those properties).
  723.  - Function: set-text-properties START END PROPS &optional OBJECT
  724.      This function completely replaces the text property list for the
  725.      text between START and END in the string or buffer OBJECT.  If
  726.      OBJECT is `nil', it defaults to the current buffer.
  727.      The argument PROPS is the new property list.  It should be a list
  728.      whose elements are property names alternating with corresponding
  729.      values.
  730.      After `set-text-properties' returns, all the characters in the
  731.      specified range have identical properties.
  732.      If PROPS is `nil', the effect is to get rid of all properties from
  733.      the specified range of text.  Here's an example:
  734.           (set-text-properties START END nil)
  735.    See also the function `buffer-substring-no-properties' (*note Buffer
  736. Contents::.) which copies text from the buffer but does not copy its
  737. properties.
  738. File: elisp,  Node: Property Search,  Next: Special Properties,  Prev: Changing Properties,  Up: Text Properties
  739. Property Search Functions
  740. -------------------------
  741.    In typical use of text properties, most of the time several or many
  742. consecutive characters have the same value for a property.  Rather than
  743. writing your programs to examine characters one by one, it is much
  744. faster to process chunks of text that have the same property value.
  745.    Here are functions you can use to do this.  They use `eq' for
  746. comparing property values.  In all cases, OBJECT defaults to the
  747. current buffer.
  748.    For high performance, it's very important to use the LIMIT argument
  749. to these functions, especially the ones that search for a single
  750. property--otherwise, they may spend a long time scanning to the end of
  751. the buffer, if the property you are interested in does not change.
  752.    Remember that a position is always between two characters; the
  753. position returned by these functions is between two characters with
  754. different properties.
  755.  - Function: next-property-change POS &optional OBJECT LIMIT
  756.      The function scans the text forward from position POS in the
  757.      string or buffer OBJECT till it finds a change in some text
  758.      property, then returns the position of the change.  In other
  759.      words, it returns the position of the first character beyond POS
  760.      whose properties are not identical to those of the character just
  761.      after POS.
  762.      If LIMIT is non-`nil', then the scan ends at position LIMIT.  If
  763.      there is no property change before that point,
  764.      `next-property-change' returns LIMIT.
  765.      The value is `nil' if the properties remain unchanged all the way
  766.      to the end of OBJECT and LIMIT is `nil'.  If the value is
  767.      non-`nil', it is a position greater than or equal to POS.  The
  768.      value equals POS only when LIMIT equals POS.
  769.      Here is an example of how to scan the buffer by chunks of text
  770.      within which all properties are constant:
  771.           (while (not (eobp))
  772.             (let ((plist (text-properties-at (point)))
  773.                   (next-change
  774.                    (or (next-property-change (point) (current-buffer))
  775.                        (point-max))))
  776.               Process text from point to NEXT-CHANGE...
  777.               (goto-char next-change)))
  778.  - Function: next-single-property-change POS PROP &optional OBJECT LIMIT
  779.      The function scans the text forward from position POS in the
  780.      string or buffer OBJECT till it finds a change in the PROP
  781.      property, then returns the position of the change.  In other
  782.      words, it returns the position of the first character beyond POS
  783.      whose PROP property differs from that of the character just after
  784.      POS.
  785.      If LIMIT is non-`nil', then the scan ends at position LIMIT.  If
  786.      there is no property change before that point,
  787.      `next-single-property-change' returns LIMIT.
  788.      The value is `nil' if the property remains unchanged all the way to
  789.      the end of OBJECT and LIMIT is `nil'.  If the value is non-`nil',
  790.      it is a position greater than or equal to POS; it equals POS only
  791.      if LIMIT equals POS.
  792.  - Function: previous-property-change POS &optional OBJECT LIMIT
  793.      This is like `next-property-change', but scans back from POS
  794.      instead of forward.  If the value is non-`nil', it is a position
  795.      less than or equal to POS; it equals POS only if LIMIT equals POS.
  796.  - Function: previous-single-property-change POS PROP &optional OBJECT
  797.           LIMIT
  798.      This is like `next-single-property-change', but scans back from
  799.      POS instead of forward.  If the value is non-`nil', it is a
  800.      position less than or equal to POS; it equals POS only if LIMIT
  801.      equals POS.
  802.  - Function: text-property-any START END PROP VALUE &optional OBJECT
  803.      This function returns non-`nil' if at least one character between
  804.      START and END has a property PROP whose value is VALUE.  More
  805.      precisely, it returns the position of the first such character.
  806.      Otherwise, it returns `nil'.
  807.      The optional fifth argument, OBJECT, specifies the string or
  808.      buffer to scan.  Positions are relative to OBJECT.  The default
  809.      for OBJECT is the current buffer.
  810.  - Function: text-property-not-all START END PROP VALUE &optional OBJECT
  811.      This function returns non-`nil' if at least one character between
  812.      START and END has a property PROP whose value differs from VALUE.
  813.      More precisely, it returns the position of the first such
  814.      character.  Otherwise, it returns `nil'.
  815.      The optional fifth argument, OBJECT, specifies the string or
  816.      buffer to scan.  Positions are relative to OBJECT.  The default
  817.      for OBJECT is the current buffer.
  818.